package org.dlow.socket.server;

import org.dlow.filter.FilterData;
import org.dlow.filter.FilterResponse;
import org.dlow.filter.server.ServerBeforeFilter;
import org.dlow.socket.codec.RpcRequest;

/**
 * @description:
 * @Author: 山沐与山
 * @CreateTime: 2024-05-17 14:14
 */
public class ServerTokenFilter implements ServerBeforeFilter {
    @Override
    public FilterResponse doFilter(FilterData<RpcRequest> filterData) {
        final RpcRequest rpcRequest = filterData.getObject();
        Object value = rpcRequest.getClientAttachments().get("token");
        if (!value.equals("dlow")){
            return new FilterResponse(false,new Exception("token 不正确,当前token为:" + value));
        }
        return new FilterResponse(true,null);
    }
}
